#!/bin/sh

die () { echo "$@" ; cleanup ; exit 1; }

cleanup() {
  unset -f curl wget
}

\. ../../../nvm.sh

\. ../../common.sh

curl() {
  return 1
}
wget() {
  return 1
}

try_err nvm_get_latest
[ "_$CAPTURED_STDERR" = "_https://latest.nvm.sh did not redirect to the latest release on GitHub" ] \
  || die "failed redirect did not report correct error message, got '$CAPTURED_STDERR'"
[ "_$CAPTURED_EXIT_CODE" = "_2" ] \
  || die "failed redirect did not exit with code 2, got $CAPTURED_EXIT_CODE"

cleanup
